import React, { useEffect, useState } from "react";
import { addToCart, getShopDetail } from "../../api";
// interface detail {
// 	name: string;
// 	image: string;
// 	id: string;
// }
export default function Detail(props: any) {
	const id = props.match.params.id;
	const [detail, setDetail] = useState<any>({});
	useEffect(() => {
		getShopDetail(id).then((res: any) => {
			setDetail(res);
		});
	}, []);
	return (
		<div>
			{detail.name}
			<img src={detail.image} alt="" />
			<button
				onClick={() => {
					addToCart(detail).then(res => {
						console.log(res);
					});
				}}
			>
				加入购物车
			</button>
		</div>
	);
}
